#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int maxn=2010, maxm=maxn*(maxn-1)/2, inf=0x7ffffff;

struct Net {
    int n, m=1, ind[maxn+1], to[2*maxm+2], link[2*maxm+2], val[2*maxm+2], dis[maxn+1], cur[maxn+1];
    bool flag=false;

    void addSide(int u, int v, int w) {
        m++;
        to[m] = v;
        val[m] = w;
        link[m] = ind[u];
        ind[u] = m;
    }

    void spfa(int s) {
        memset(dis, 127, sizeof dis);
        dis[s] = 0;
        static int que[maxn+1];
        static bool book[maxn+1];
        int h=0, t=1;
        que[1] = s;
        book[s] = true;
        for (; h!=t; ) {
            h = h%n+1;
            int o=que[h];
            book[o] = false;
            for (int i=ind[o]; i; i=link[i]) {
                if (val[i] && dis[to[i]]>dis[o]+1) {
                    dis[to[i]] = dis[o]+1;
                    if (!book[to[i]]) {
                        t = t%n+1;
                        book[que[t] = to[i]] = true;
                    }
                }
            }
        }
    }

    int run(int o, int t, int flow) {
        if (o==t) return flow;
        int have=0;
        for (int i=cur[o]; i; i=link[i]) {
            cur[o] = i;
            if (val[i] && dis[to[i]]==dis[o]+1) {
                int temp=run(to[i], t, min(flow-have, val[i]));
                val[i]-=temp, val[i^1]+=temp;
                have+=temp;
                if (flow==have) return have;
            }
        }
        return have;
    }

    int solve(int s, int t) {
        int ret=0;
        for (; ; ) {
            memcpy(cur, ind, sizeof ind);
            spfa(s);
            if (dis[t]>n) return ret;
            else ret = ret+run(s, t, inf);
        }
    }
};

int main() {
    freopen("leaflike.in", "r", stdin);
    freopen("leaflike.out", "w", stdout);

    static bool book[maxn+1], map[maxn+1][maxn+1];
    static Net g;
    int n, m, a=0, b=0;
    scanf("%d %d", &n, &m);
    g.n = n+2;
    for (int i=1; i<=n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        if ((x+y)%2) {
            b++;
            book[i] = true;
            g.addSide(i, n+2, 1);
            g.addSide(n+2, i, 0);
        } else {
            a++;
            g.addSide(n+1, i, 1);
            g.addSide(i, n+1, 0);
        }
    }

    if (!m) printf("%d\n", max(a, b));
    else {
        for (int i=1; i<=m; i++) {
            int p, q;
            scanf("%d %d", &p, &q);
            map[p][q] = map[q][p] = true;
        }
        for (int i=1; i<=n; i++) {
            for (int j=1; j<=n; j++) {
                if (!book[i] && book[j] && !map[i][j]) {
                    g.addSide(i, j, 1);
                    g.addSide(j, i, 0);
                }
            }
        }
        printf("%d\n", n-g.solve(n+1, n+2));
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
